package com.gxuwz.leave.service;

import com.gxuwz.leave.dao.StuDao;
import com.gxuwz.leave.entity.Student;

import java.util.List;

public class StuServiceImpl implements StuService{
    private StuDao stuDao;
    @Override
    public void addStu(Student entity) {
        stuDao.insert(entity);
    }

    @Override
    public Student findStu(String StuID) {
        Student stu = new Student();
        stu.setStuID(StuID);
        List<Student> students = stuDao.query(stu);
        if(students!=null){
            stu = students.get(0);
        }
        return stu;
    }

    @Override
    public void deleteStu(String StuID) {
        stuDao.delete(StuID);
    }

    @Override
    public List<Student> list(Student entity) {
        return stuDao.query(entity);
    }

    @Override
    public void editStu(Student entity) {
        stuDao.update(entity);
    }

    @Override
    public boolean checkStu(String username, String password) {
        Student stu = new Student();
        stu.setStuID(username);
        stu.setPassword(password);
        List<Student> students= stuDao.query(stu);
        return !students.isEmpty();
    }

    public void setStuDao(StuDao stuDao) {
        this.stuDao = stuDao;
    }
}
